from bs4 import BeautifulSoup

html = """
<html>
<head><title>黑马程序员</title></head>
<body>
<p id="test01">软件测试</p>
<p id="test02">2020年</p>
<a href="/api.html">接口测试</a>
<a href="/web.html">Web自动化测试</a>
<a href="/app.html">APP自动化测试</a>
</body>
</html>
"""
soup = BeautifulSoup(html, "html.parser")
print(soup.title)  # 获取title标签
print(soup.title.name)  # 获取title标签的名称
print(soup.title.string)  # 获取title标签的文本内容
print(soup.p)  # 获取第一个p标签
print(soup.p["id"])  # 获取第一个p标签的id属性值
for i in soup.find_all("a"):
    print("href = {}".format(i['href']))
    print('value = {}'.format(i.string))

data = '''
<form name='easypaysubmit' id='easypaysubmit' target='_blank' method='post' action='http://mertest.chinapnr.com/muser/publicRequests'>
<input name='Version' type='hidden' value='10'/>
<input name='CmdId' type='hidden' value='UserRegister'/>
<input name='MerCustId' type='hidden' value='6000060007313892'/>
<input name='BgRetUrl' type='hidden' value='https://www.baidu.com/'/>
<input name='RetUrl' type='hidden' value='http://dev-www.zcbk.deayou.com/trust/chinapnr/register/return/20011318124917315444'/>
<input name='UsrId' type='hidden' value=''/>
<input name='UsrName' type='hidden' value=''/>
<input name='IdType' type='hidden' value='00'/>
<input name='IdNo' type='hidden' value='51343620000113288X'/>
<input name='UsrMp' type='hidden' value='13210001001'/>
<input name='UsrEmail' type='hidden' value=''/>
<input name='MerPriv' type='hidden' value='20011318124917315444'/>
<input name='ChkValue' type='hidden' value='1784F61D7A6FDB0C900808DEA6DCEA882A138E731234473B84CB2829DF2B66FF032E40697D9668DC4B054A2790BDCF1EF32D2DB4B807CAF7F89829BE7C10520C3AF44DEF8EA2DDD07141C49DDEC147ECEC6A3D8E7E3B751D5308171AB3131668D19822D7F05E2E7CAAC5DB1F5744821B4A8B439E9A4335614B6A2CD8E3467DE5'/>
<input name='CharSet' type='hidden' value='UTF-8'/>
</form>
<script>document.forms['easypaysubmit'].submit();</script>
'''
soup = BeautifulSoup(data, 'html.parser')

url = soup.form['action']
print(url)
data_dict = {}
print(type(data_dict))
for i in soup.find_all('input'):
    data_dict.update({i['name']: i['value']})
print(data_dict)





























